/**
 * Created by cjd on 2016/5/4.
 */
angular.module("app").factory("timestampMarker", ["$rootScope", "$timeout", function ($rootScope, $timeout) {
    return {
        request: function (config) {
            var headersGetter = config.headers;
            if ((headersGetter["Accept"] && headersGetter["Accept"].split(",")[0]) == "application/json" && config["url"].indexOf("template") < 0) {
                $rootScope.loading = true;
                config.requestTimestamp = new Date().getTime();
                config.url = $rootScope.sysOrigin + config.url;
            }
            return config;
        },
        response: function (response) {
            // $timeout(function () {
            //     $rootScope.loading = false;
            // }, 500);
            response.config.responseTimestamp = new Date().getTime();
            return response;
        }
    };
}]);
angular.module("app")
    .factory("User", ["$resource", function ($resource) {
        return $resource("", {}, {
            Login: {
                cache: false,
                method: "POST",
                url: "/user/login",
                isArray: false
            },
            sendSMS: {
                cache: false,
                method: "POST",
                url: "/user/sendCode",
                isArray: false
            },
            checkPassword: {
                cache: false,
                method: "POST",
                url: "/user/checkPassword",
                isArray: false
            },
            updatePassword: {
                cache: false,
                method: "POST",
                url: "/user/updatePassword",
                isArray: false
            },
            resetPassword: {
                cache: false,
                method: "POST",
                url: "/user/resetPassword",
                isArray: false
            },
            getList: {
                cache: false,
                method: "POST",
                url: "/user/listByOrgId",
                isArray: false
            },
            saveUser: {
                cache: false,
                method: "POST",
                url: "/user/save",
                isArray: false
            },
            updateStatus: {
                cache: false,
                method: "POST",
                url: "/user/updateStatus",
                isArray: false
            }
        });
    }])
    .factory("org", ["$resource", function ($resource) {
        return $resource("", {}, {
            count: {
                cache: false,
                method: "POST",
                url: "/index/count",
                isArray: false
            },
            getTreeData: {
                cache: false,
                method: "POST",
                url: "/org/test",
                isArray: false
            },
            updateStatus: {
                cache: false,
                method: "POST",
                url: "/org/updateStatus",
                isArray: false
            },
            saveOrg: {
                cache: false,
                method: "POST",
                url: "/org/save",
                isArray: false
            },
            getList: {
                cache: false,
                method: "POST",
                url: "/org/list",
                isArray: false
            }
        });
    }])
    .factory("group", ["$resource", function ($resource) {
        return $resource("", {}, {
            listByOrg: {
                cache: false,
                method: "POST",
                url: "/group/listByOrg",
                isArray: false
            },
            unlist: {
                cache: false,
                method: "POST",
                url: "/group/findUnAffiliated",
                isArray: false
            },
            volListById: {
                cache: false,
                method: "POST",
                url: "/group/volListById",
                isArray: false
            },
            getGroupInfo: {
                cache: false,
                method: "POST",
                url: "/group/info",
                isArray: false
            }
        });
    }])
    .factory("activitySign", ["$resource", function ($resource) {
        return $resource("", {}, {
            listByUser: {
                cache: false,
                method: "POST",
                url: "/activitySign/listByUser",
                isArray: false
            }
        });
    }])
    .factory("groupVerify", ["$resource", function ($resource) {
        return $resource("", {}, {
            getList: {
                cache: false,
                method: "POST",
                url: "/orgVerify/list",
                isArray: false
            },
            checkFail: {
                cache: false,
                method: "POST",
                url: "/orgVerify/checkFail",
                isArray: false
            },
            checkSuccess: {
                cache: false,
                method: "POST",
                url: "/orgVerify/checkSuccess",
                isArray: false
            }
        });
    }])
;